#ifndef __BASIC_TASK_EXECUTOR_H__
#define __BASIC_TASK_EXECUTOR_H__

#include <memory>
#include "basic/platform.h"
#include "basic/types.h"
#include "basic/tpl_singleton.h"

namespace basic {
M_API_FUNC enum class ETaskStatus : short {
  UNKNOWN = -1,
  INITED = 0,
  READY_TO_EXECUTE,
  EXECUTING,
  DONE,
  FAILED,
};

M_API_FUNC class DKTask {
public:
  DKTask() = default;
  virtual ~DKTask(){};
  int GetID() {
    return m_iID;
  }
  virtual bool Execute() {
    return false;
  }
  ETaskStatus GetStatus() const {
    return m_status;
  }
  void SetStatus(ETaskStatus v) {
    m_status = v;
  }

private:
  static int s_iTaskID;
  int m_iID{s_iTaskID++};
  friend class DKTaskExecutor;
  ETaskStatus m_status{ETaskStatus::UNKNOWN};
};

M_API_FUNC class DKTaskExecutor final : public tpl_Singleton<DKTaskExecutor> {
  M_SINGLETON_DECLARE(DKTaskExecutor)
public:
  bool AddTask(std::shared_ptr<DKTask>& t);
  bool RemoveTask(std::shared_ptr<DKTask>& t);

private:
  void Init() override;
  void DeInit() override;
};
} // namespace basic

#endif // DUCK_DK_TASK_EXECUTOR_H
